import { http } from '@/utils/http'
import { baseUrlApi } from './utils'
import type { ResponseType } from '@/utils/http/types'

export type UserResult = {
  /** 用户名 */
  username: string
  /** `token` */
  accessToken: string
  /** 用于调用刷新`accessToken`的接口时所需的`token` */
  refreshToken: string
  /** `accessToken`的过期时间（格式'xxxx/xx/xx xx:xx:xx'） */
  expires: Date
}

/** 登录 */
export const getLogin = (data?: object) => {
  return http.request<ResponseType<UserResult>>('post', baseUrlApi('login'), { data })
}

/** 登录 */
export const getTest = (params?: object) => {
  return http.request<ResponseType<UserResult>>('get', baseUrlApi('test'), { params })
}
